const express = require('express')
const app = express()
app.use(express.urlencoded({ extended: false }))
const db = require('./database/app')
app.post('/api/reguser', function (req, res) {
    let { username, password } = req.body
    let sql = `select * from user where username = "${username}"`
    db(sql, (err, results) => {
        if (err) {
            return res.send({ status: 1, msg: 'sql语法错误' + err.message });
        }
        if (results.length >= 1) {
            return res.send({ status: 1, msg: '语法错误' + err.message })
        }
        let sql = `insert into user set username="${username}",password="${password}"`
        db(sql, (err, results) => {
            if (err) {
                return res.send({ status: 1, msg: '添加错误' });
            }
            if (results.affectedRows == 0) {
                return res.send({ status: 1, msg: '添加错误' })
            } 
            res.send('获取成功')
        })
       
    })
})
app.listen(3006, () => {
    console.log('http://localhost:3006');
})